<template>
    <div class="icons-bg">
      <swiper :options="swiperOption">
        <swiper-slide v-for="(item) of pages" :key="item.id">
          <div class="icons-cont" v-for="(items,index) of item" :key="index">
            <div class="icons-img">
              <img class="img-sty" :src='items.imgUrl' alt="">
            </div>
            <p class="icons-tips">{{items.desc}}</p>
          </div>
        </swiper-slide>
      </swiper>
    </div>
</template>

<script>
export default {
  name: 'icons',
  data () {
    return {
      iconsList: [{
        id: '001',
        imgUrl: 'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
        desc: '景点门票'
      }, {
        id: '002',
        imgUrl: 'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
        desc: '景点门票'
      }, {
        id: '003',
        imgUrl: 'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
        desc: '景点门票'
      }, {
        id: '004',
        imgUrl: 'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
        desc: '景点门票'
      }, {
        id: '005',
        imgUrl: 'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
        desc: '景点门票'
      }, {
        id: '006',
        imgUrl: 'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
        desc: '景点门票'
      }, {
        id: '007',
        imgUrl: 'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
        desc: '景点门票'
      }, {
        id: '008',
        imgUrl: 'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
        desc: '景点门票'
      }, {
        id: '009',
        imgUrl: 'https://s.qunarzz.com/homenode/images/touchheader/hotel.png',
        desc: '景点门票'
      }],
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    // eslint-disable-next-line vue/return-in-computed-property
    pages () {
      const pages = []
      this.iconsList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style scoped lang="stylus">
  .icons-bg >>> .swiper-container
    height: 0
    padding-bottom 50%
  .icons-cont
    position relative
    overflow hidden
    width 25%
    float left
    padding-bottom 25%
    .icons-img
      position absolute
      top 0
      left 0
      top 0
      bottom .44rem
      box-sizing border-box
      padding: .1rem
      .img-sty
        display: block
        margin 0 auto
        height: 100%
    .icons-tips
      position: absolute
      left: 0
      right: 0
      bottom: 0
      height: .44rem
      line-height: .44rem
      text-align: center
      color: #333
</style>
